#pragma once

class Font;

class ICtrl
{
public:
	enum AttachedTo
	{
	    NW = 1,
	    NE,
	    SE,
	    SW
	};

	ICtrl(ICtrl* parent, const std::string& name);
	virtual ~ICtrl();

	/*--------------------------------------------------------------------------*/
	virtual void Draw() = 0;
	/*--------------------------------------------------------------------------*/
	virtual void OnLMBClick(const glm::vec2& clickPosition);
	virtual void OnRMBClick(const glm::vec2& clickPosition);
	virtual void OnLMBDrag(const glm::vec2& clickPosition, const glm::vec2& movement);
	virtual void OnRMBDrag(const glm::vec2& clickPosition, const glm::vec2& movement);
	virtual void OnCMouseOver();
	virtual void OnCMouseIn();
	virtual void OnCMouseOut();
	virtual void ReadSpecials(std::ifstream& file, const std::string& firstWord);
	/*--------------------------------------------------------------------------*/

	ICtrl* GetParent() const;

	const glm::vec2& GetPosition() const;
	void SetPosition(const glm::vec2& npos);

	const AttachedTo& GetAttachedTo() const;
	void SetAttachedTo(const AttachedTo& att);

	const glm::vec2& GetSize() const;
	void SetSize(const glm::vec2& nsize);

	bool Check();

protected:
	void CallChildsDraw();

	bool m_CMouseOver;
	bool m_CMouseIn;
	bool m_CMouseOut;
	bool m_CMouseLMBDrag;
	bool m_CMouseRMBDrag;
	bool m_CMouseLMBClick;
	bool m_CMouseRMBClick;

	glm::vec2 m_size;
	glm::vec2 m_position;
	glm::vec2 m_sizePosition;

	glm::vec2 m_screenPosition;
	glm::vec2 m_screenSizePosition;

	AttachedTo m_attachedTo;
	std::string m_name;
	ICtrl* m_parent;

private:
	void AddChild(ICtrl* child);

	std::vector<ICtrl*> m_children;
	uint m_childrenCount;

	void CalculateScreenPosition();
	bool CallChildsCheck();

	glm::vec2 m_LMBDragLastPosition;
	glm::vec2 m_RMBDragLastPosition;
};